package com.mediacloud.app.newsmodule.fragment.video.vod

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.eventTrack.TXReportManager
import com.mediacloud.app.model.news.ArticleItem
import com.mediacloud.app.model.news.CatalogItem
import com.mediacloud.app.newsmodule.R
import com.mediacloud.app.newsmodule.activity.microlive.BaseRecyclerAdapterX
import com.mediacloud.app.newsmodule.adaptor.component.IEvent
import com.mediacloud.app.newsmodule.fragment.BigVideoViewHolder
import com.mediacloud.app.newsmodule.utils.NewsItemClickUtils


class VideoSeamlessNewListAdapter( context: Context) : BaseRecyclerAdapterX<ArticleItem>(context),
    View.OnClickListener {

    var catalogItem: CatalogItem? = null
    var events: ArrayList<IEvent> = ArrayList()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BigVideoViewHolder {
        return BigVideoViewHolder(LayoutInflater.from(context).inflate(R.layout.item_info_seamless_big, parent, false))
    }


    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        if (holder is BigVideoViewHolder) {
            holder.setInfo(getItem(position))
            holder.itemView.tag = position
            holder.itemView.setOnClickListener {
                val position = it?.tag as Int
                val item = data[position] as ArticleItem
                NewsItemClickUtils.OpenItemNewsHandle(
                    context,
                    item.type,
                    item,
                    catalogItem ?: CatalogItem()
                )

                if ("视频" == TXReportManager.getInstance().firstTabInfo.tabName) {
                    TXReportManager.getInstance().app_jhapp_video_interact("点击查看",catalogItem?.name, item,position)
                }
            }
            events.add(holder)
        }
    }


    override fun getItemCount(): Int {
        return data.size
    }

    fun destroy() {
        for (event in events) {
            event.destroy()
        }
        events.clear()
    }

}